﻿@{
    ViewBag.Title = "添加关联课程";
}
@section headerSection{
    <style>
        #exampleToolbar > .form-group {
            float: left;
            margin: 0;
            margin-left: 5px;
        }
    </style>
}
<div class="animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins" style="margin-bottom: 0px;">
        <div class="ibox-content" style="padding: 5px 20px 0px 20px;">
            <div class="row row-lg">
                <div class="col-sm-12 col-sm-leftRight">
                    <!-- Example Toolbar -->
                    <div class="example">
                        <div class="btn-group hidden-xs" id="exampleToolbar" role="group">
                            <div class="form-group" style="margin:0;">
                                <input id="keyword" name="keyword" type="text" style="width:250px;" class="form-control" placeholder="请输入名称/path/分组">
                            </div>
                            <div class="form-group">
                                <button id="btnSearch" class="btn btn-primary" type="button"><i class="fa fa-search"></i>&nbsp;查询</button>
                            </div>
                        </div>
                        <table id="exampleTableToolbar" data-mobile-responsive="true" data-radio="true"></table>
                    </div>
                    <!-- End Example Toolbar -->
                </div>
            </div>
        </div>
    </div>
    <!-- End Panel Other -->
</div>
@section footSection{
    <script>
        var $table, addOrEditUrl, options, store_id;
        var circleAddManager = {
            initPage: function () {
                if (!circleAddManager.initData()) {
                    layer.msg("店铺id参数异常！", { icon: 5 });
                    return false;
                }
                circleAddManager.initTable();
                circleAddManager.bindEvent();
            },
            initData: function () {
                store_id = $.getUrls('store_id');
                if (store_id)
                    return true;
                return false;
            },
            //1.0 初始化Table
            initTable: function () {
                options = {
                    url: ctx + "/VRCircle/InitCircleRelTable",
                    cutHeight: 5,
                    singleSelect: false,
                    toolbar: "#exampleToolbar",
                    queryParams: function (params) {
                        params = {
                            //页面大小
                            rows: params.limit,
                            //第几页
                            page: params.offset / params.limit + 1,
                            store_id: store_id,//店铺id
                            keyword: encodeURI($('#keyword').val()) //关键字
                        }
                        return params;
                    },
                    columns: [
                        {
                            checkbox: true
                        }, {
                            field: 'folder_order',//第一列序号
                            title: '序号',
                            align: 'center',
                            width: 50
                        }, {
                            field: 'folder_name',
                            title: '节点名称',
                            align: 'center'
                        }, {
                            field: 'pro_type',
                            title: '产品类别',
                            align: 'center',
                            formatter: function (value, row, index) {
                                switch (value) {
                                    case 1: return "VR作品";break;
                                    case 2: return "虚仿课程"; break;
                                    case 3: return "头记"; break;
                                    case 4: return "校史馆"; break;
                                    default: return "商城"; break;
                                }
                            }
                        }, {
                            field: 'group_name',
                            title: '分组名称',
                            align: 'center'
                        }, {
                            field: 'is_recommend',
                            title: '推荐',
                            align: 'center',
                            formatter: function (value, row, index) {
                                if (value)
                                    return "是";
                                return "否";
                            }
                        }, {
                            field: 'folder_path',
                            title: 'path',
                            align: 'center'
                        }, {
                            field: 'folder_note',
                            title: '备注',
                            align: 'center'
                        }, {
                            field: 'update_date',
                            title: '更新时间',
                            align: 'center'
                        }, {
                            field: 'update_name',
                            title: '更新人',
                            align: 'center',
                            formatter: function (value, row, index) {
                                if (!value)
                                    return row.create_name;
                                return value;
                            }
                        }, {
                            field: 'create_time',
                            title: '创建时间',
                            align: 'center'
                        }, {
                            field: 'create_name',
                            title: '创建人',
                            align: 'center'
                        }]
                }
                $table = tableHelper.initTable("exampleTableToolbar", options);
            },
            //2.0 返回选中行
            selections: function (isAll) {
                var row = $table.bootstrapTable('getSelections');
                if (!row || row.length === 0) {
                    layer.msg("数据为空或未选中记录行~", { icon: 5 });
                    return false;
                }
                if (isAll)
                    return row;
                if (row.length > 1) {
                    layer.msg("当前操作不支持多选，请选择一行再操作！", { icon: 5 });
                    return false;
                }
                return row[0];
            },
            //3.0 绑定事件
            bindEvent: function () {
                //查询
                $('#btnSearch').click(function () {
                    $table.bootstrapTable('refresh', options);
                });
            },
            //4.0 获取添加关联的课程
            getCircleRelData: function () {
                var row = circleAddManager.selections(true);
                if (!row || row.length <= 0)
                    return false;
                var addId = new Array();
                $.each(row, function (index, item) {
                    addId.push(item.id);
                });
                return addId.join(',');
            }
        }
        $(function () {
            //初始化页面
            circleAddManager.initPage();
        });
    </script>
}